********************************************************************************
**      TITLE: Making graphs for SSN resarch of a2i
**
**      PROJECT: Information and power asymmetry in digitalised SSN system
**
**      PURPOSE: Making graphs to analyse 
**		information and power asymmetry in digitalised SSN system
**
**      CREATED: 14 July 2022 | Time: 8:32 pm
**
**                                                                                                      
********************************************************************************



**# Setup Stata
*------------------------------------------------------------------------------*
        
        cls
        clear                   all
        macro drop              _all
        version                 14
        set min_memory  		1g 
        set maxvar              32767
        set more                off
        discard 
        set seed                87235
        set sortseed    98237
        set niceness    1
        set traced              1
        pause                   on
        
		
		/*Set the folder structure in the following manner to have the do files
		run properly:
		
		1. Codes -> Subfolder "01_Ado". Put all the do files in Codes
		
		2. Data -> Subfolder "Raw" and "Clean"
		
		Place the dataset "a2i_SSN" in "Raw"
		*/


		  **# Global Path
        *------------------------------------------------------------------------------*
                
        * Setup working directory
        *------------------------
                if "$cwd" ~= "" cd "$cwd"
                else global cwd "`c(pwd)'"
                sysdir set PLUS "01_Ado/"
		
		 **# Install user programs
        *----------------------
                cap which blindschemes
                if _rc ssc install blindschemes
				
				cap which grstyle
                if _rc ssc install grstyle


				
		



do "ssn_a2i_n.do"



set scheme plottigblind, permanently
grstyle init
grstyle color background white


global skyblue "86 180 233"
	global blue "0 114 178"
	global teal "17 222 245"
	global orange "213 94 0"
	global green "0 158 115"
	global yellow "230 159 0"
	global purple "204 121 167"
	global lavendar "154 121 204"
	global cherry "200 0 0"
    global tangerine "255 86 29"

	
	**sequential color
	global blue1 "158 202 225"
	global blue2 "66 146 198"
	global blue3 "8 81 156"
	
	global purple1 "188 189 220"
	global purple2 "128 125 186"
	global purple3 "84 39 143"



//naming the graph details
//main details
global gr_deets percentages asyvars ylabel(0(25)100, labsize(large) labcolor (black)) ///
blabel(bar, format(%4.1f) size(large)color (black) position(outside)) ///
bar(1, bcolor("$blue"))bar(2, bcolor("$purple"))bar(3, bcolor("$orange")) ///
bar(4, bcolor("$teal"))bar(5, bcolor("$green")) bar(6, bcolor("$yellow")) ///
bar(7, bcolor("$lavendar")) bar(8, bcolor("$skyblue")) bar(9, bcolor("$cherry")) ///
 bar(10, bcolor("$tangerine")) legend(label (1 "Yes") label (2 "No") row(1) ///
 pos(6) size(large))

global gr_deets2 percentages asyvars ylabel(0(25)100, labsize(large) labcolor (black)) ///
blabel(bar, format(%4.0f) size(large)color (black) position(outside)) ///
bar(1, bcolor("$blue"))bar(2, bcolor("$purple"))bar(3, bcolor("$orange")) ///
bar(4, bcolor("$teal"))bar(5, bcolor("$green")) bar(6, bcolor("$yellow")) ///
bar(7, bcolor("$lavendar")) bar(8, bcolor("$skyblue")) bar(9, bcolor("$cherry")) ///
bar(10, bcolor("$tangerine")) legend(label (1 "Yes") label (2 "No") row(1) ///
pos(6) size(large))

global gr_deets3 percentages asyvars ylabel(0(25)100, labsize(large) labcolor (black)) ///
blabel(bar, format(%4.0f) size(medium)color (black) position(outside)) ///
bar(1, bcolor("$blue"))bar(2, bcolor("$purple"))bar(3, bcolor("$orange")) ///
bar(4, bcolor("$teal"))bar(5, bcolor("$green")) bar(6, bcolor("$yellow")) ///
bar(7, bcolor("$lavendar")) bar(8, bcolor("$skyblue")) bar(9, bcolor("$cherry")) ///
bar(10, bcolor("$tangerine")) legend(label (1 "Yes") label (2 "No") row(1) ///
pos(6) size(large))

global gr_deets4 percentages asyvars ylabel(0(25)100, labsize(large) labcolor (black)) ///
blabel(bar, format(%4.1f) size(large)color (black) position(outside)) ///
bar(1, bcolor("$blue"))bar(2, bcolor("$purple"))bar(3, bcolor("$orange")) ///
bar(4, bcolor("$teal"))bar(5, bcolor("$green")) bar(6, bcolor("$yellow")) ///
bar(7, bcolor("$lavendar")) bar(8, bcolor("$skyblue")) bar(9, bcolor("$cherry")) ///
bar(10, bcolor("$tangerine")) legend(label (1 "Yes") label (0 "No") row(1) ///
pos(6) size(large))


//note details for beneficiary
global gr_all ytitle("", size(small))note("N=531",size(large)) plotregion(fcolor(white))
global gr_ben ytitle("", size(small))note("N=395",size(large)) plotregion(fcolor(white))

global gr_gender ytitle("", size(small))note("N=395 M=142; F=253",size(large))plotregion(fcolor(white))

global gr_region ytitle("", size(small))note("N=395 R=201; U=194",size(large)) plotregion(fcolor(white))

global gr_g_r ytitle("", size(small))note("N=395; (M=142; F=253); (R=201; U=194)",size(large)) plotregion(fcolor(white))

global gr_cat ytitle("", size(small)) ///
note("N=395; Poor=140; Rich=136; Average=134; Haor=42; Coastal=40; Hill tracts=39",size(small)) plotregion(fcolor(white))

global gr_cat_g ytitle("", size(small)) ///
note("N=395; (M=142; F=253); (Poor=140; Rich=136; Average=134; Haor=42; Coastal=40; Hill tracts=39)",size(small)) plotregion(fcolor(white))

global gr_cat_r ytitle("", size(small)) ///
note("N=395; (R=201; U=194); (Poor=140; Rich=136; Average=134; Haor=42; Coastal=40; Hill tracts=39)",size(small)) plotregion(fcolor(white))


global gr_ben_t ytitle("", size(small)) ///
note("N=395; Old=200; Widow=86; Disabled=74; Poor mothers=28; Edu. stipend for disabled=4; Marginalised=3",size(small)) plotregion(fcolor(white))

//note details for non beneficiary
global gr_ben_nonben ytitle("", size(small)) ///
note("N=531; Ben=395; Non-ben=136",size(small)) plotregion(fcolor(white))

global gr_nonben ytitle("", size(small)) ///
note("N=136",size(large)) plotregion(fcolor(white))

global gr_nonben_gender ytitle("", size(small))note("N=136; M=48; F=88",size(small)) plotregion(fcolor(white))

global gr_nonben_region ytitle("", size(small))note("N=136; R=68; U=68",size(small)) plotregion(fcolor(white))

global gr_nonben_g_r ytitle("", size(small))note("N=136; (M=48; F=88); (R=68; U=68)",size(small)) plotregion(fcolor(white))


global gr_nonben_cat ytitle("", size(small)) ///
note("N=136; Poor= 36; Rich=33; Average=33; Haor=12; Coastal=12; Hill tracts=10",size(small)) plotregion(fcolor(white))


global gr_nonben_cat_g ytitle("", size(small)) ///
note("N=136; (M=48; F=88); (Poor= 36; Rich=33; Average=33; Haor=12; Coastal=12; Hill tracts=10)",size(small)) plotregion(fcolor(white))

global gr_nonben_cat_r ytitle("", size(small)) ///
note("N=136; (R=68; U=68); (Poor= 36; Rich=33; Average=33; Haor=12; Coastal=12; Hill tracts=10)",size(small)) plotregion(fcolor(white))

global gr_ben_n ytitle("", size(small)) ///
note("N=136; Old= 67; Widow=31; Disabled=23; Poor mothers=9; Marginalised=4; Disabled stipend=2",size(small)) plotregion(fcolor(white))


//ind char notes

global gr_nonben_emp ytitle("", size(small))note("N=136; Employed=37; Unemployed=99",size(small)) plotregion(fcolor(white)) 

global gr_nonben_la ytitle("", size(small))note("N=136; Zero=105; One-Fifty=21; Fifty one-One sixty=10",size(small)) plotregion(fcolor(white)) 

global gr_nonben_bp ytitle("", size(small)) note("N=136; Zero= 14; One= 102; Two=18; Three=2",size(small)) plotregion(fcolor(white))

global gr_nonben_sp ytitle("", size(small))note("N=136; Zero=89; One=41; Two=6",size(small)) plotregion(fcolor(white)) 


////////////////////////////Graphs begin here//////////////////////////////

//employment status

gen n_emp_new=.

recode n_emp_new .=1 if n_emp==1 & ben1==1
recode n_emp_new .=2 if n_emp==0 & ben1==1

la def n_emp_new 1 "Yes" 2 "No", modify
la val n_emp_new n_emp_new

graph bar (percent),over(n_emp_new, gap(80) label(labcolor(black))) ///
percentages asyvars ylabel(0(25)100, labsize(large) labcolor (black)) ///
blabel(bar, format(%4.1f) size(large)color (black) position(outside)) ///
bar(1, bcolor("$blue"))bar(2, bcolor("$purple"))bar(3, bcolor("$orange")) ///
bar(4, bcolor("$teal"))bar(5, bcolor("$green")) bar(6, bcolor("$yellow")) ///
bar(7, bcolor("$lavendar")) bar(8, bcolor("$skyblue")) bar(9, bcolor("$cherry")) ///
bar(10, bcolor("$tangerine")) title("Beneficiary is employed (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_ben name(e1, replace)
 




//additional help to verify
graph pie,over(add_help) pie(1, color("$blue1")) pie(2, color("$lavendar")) ///
 noclockwise scheme(vg_lgndc) plabel(_all percent, format("%2.1f") size(large) ///
 color(white)) legend (label (1 "Yes")) legend (label (2 "No"))  ///
 title("Additional help to verify the eligibility of docs  (%)", justification(left) ///
 margin(b+1 t-1 l-1) bexpand size(large) color (black))  note("N=395",size(large)) ///
 plotregion(color(white) fcolor(white) icolor(white) ifcolor(white) lcolor(white) ///
 ilcolor(white)) graphregion(color(white) fcolor(white) icolor(white) ifcolor(white) ///
 lcolor(white) ilcolor(white))name(pie1, replace)

graph pie,over(add_help)by(gender, ///
title("Additional help to verify the eligibility of docs by gender (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
note("N=395; M=142; F=253",size(large))) pie(1, color("$blue1")) ///
pie(2, color("$lavendar"))  noclockwise scheme(vg_lgndc) ///
plabel(_all percent, format("%2.1f") size(vlarge) color(white)) ///
legend (label (1 "Yes")) legend (label (2 "No"))  name(pie2, replace)

graph pie,over(add_help)by(region, ///
title("Additional help to verify the eligibility of docs by strata (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
note("N=395; R=201; U=194",size(large))) pie(1, color("$blue1")) ///
pie(2, color("$lavendar"))  noclockwise scheme(vg_lgndc) plabel(_all percent, ///
format("%2.1f") size(vlarge) color(white)) legend (label (1 "Yes")) ///
legend (label (2 "No"))  name(pie3, replace)


gr combine pie1 pie2 pie3, altshrink




//Require approval of elites

graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
$gr_deets2 title("Require approval of local politician/elite (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_ben name(a1, replace)


graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(gender, gap(200) label(labcolor(black) labsize (large)))  ///
$gr_deets2 title("Require approval of local politician/elite by gender (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_gender name(a2, replace)

graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(region, gap(200) label(labcolor(black) labsize (large))) $gr_deets2 ///
title("Require approval of local politician/elite by strata (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_region name(a3, replace)

graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(gender, gap(200) label(labcolor(black) labsize (large))) ///
over(region, gap(200) label(labcolor(black) labsize (large))) ///
$gr_deets2 title("Require approval of local politician/elite by gender and strata (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_g_r name(a4, replace)



gr combine a1 a2 a3 a4, altshrink


graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(cat_district, gap(200) label(labcolor(black) labsize (large))) ///
$gr_deets2 title("Require approval of local politician/elite by category of district", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_cat name(a5, replace)



graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(gender, gap(80) label(labcolor(black) labsize ())) ///
over(cat_district, gap(200) label(labcolor(black) labsize (large))) ///
$gr_deets2 title("Require approval of local politician/elite by gender and district (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_cat_g name(a6, replace)


graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(region, gap(80) label(labcolor(black) labsize ())) over(cat_district, gap(200) ///
label(labcolor(black) labsize (large))) $gr_deets2 ///
title("Require approval of local politician/elite by strata and district (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_cat_r name(a7, replace)


graph bar (percent),over(oth_val, gap(80) label(labcolor(black))) ///
over(ben_t, gap(200) label(labcolor(black) labsize ())) $gr_deets2 ///
title("Require approval of local politician/elite by beneficiary type (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_ben_t name(a8, replace)




gr combine a5 a6 a7 a8, altshrink





//Informal fees

graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
$gr_deets2 title("Informal fee for registration (%)", justification(left) ///
margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_ben name(i1, replace)


graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(gender, gap(200) label(labcolor(black) labsize (large)))  ///
$gr_deets2 title("Informal fee for registration by gender (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_gender name(i2, replace)

graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(region, gap(200) label(labcolor(black) labsize (large))) $gr_deets2 ///
title("Informal fee for registration by strata (%)", justification(left) ///
margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_region name(i3, replace)

graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(gender, gap(200) label(labcolor(black) labsize (large))) ///
over(region, gap(200) label(labcolor(black) labsize (large))) ///
 $gr_deets2 title("Informal fee for registration by gender and strata (%)", ///
 justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
 $gr_g_r name(i4, replace)



gr combine i1 i2 i3 i4, altshrink


graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(cat_district, gap(200) label(labcolor(black) labsize (large))) ///
$gr_deets2 title("Informal fee for registration by category of district", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_cat name(i5, replace)



graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(gender, gap(80) label(labcolor(black) labsize ())) over(cat_district, ///
gap(200) label(labcolor(black) labsize (large))) $gr_deets2 ///
title("Informal fee for registration by gender and district (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_cat_g name(i6, replace)


graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(region, gap(80) label(labcolor(black) labsize ())) over(cat_district, ///
gap(200) label(labcolor(black) labsize (large))) $gr_deets2 ///
title("Informal fee for registration by strata and district (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_cat_r name(i7, replace)


graph bar (percent),over(reg_fee, gap(80) label(labcolor(black))) ///
over(ben_t, gap(200) label(labcolor(black) labsize ())) $gr_deets2 ///
title("Informal fee for registration by beneficiary type (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black))$gr_ben_t name(i8, replace)




gr combine i5 i6 i7 i8, altshrink




//who received the fees
graph pie,over(pay_whom) pie(1, color("$blue1")) pie(2, color("$lavendar"))  ///
noclockwise scheme(vg_lgndc) plabel(_all percent, format("%2.0f") size(large) color(white)) ///
title("Who received the informal payment? (%)", justification(left) margin(b+1 t-1 l-1) ///
bexpand size(large) color (black))  note("N=56",size(medium)) plotregion(color(white) ///
fcolor(white) icolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
graphregion(color(white) fcolor(white) icolor(white) ifcolor(white) lcolor(white) ///
ilcolor(white))name(w1, replace)

graph pie,over(pay_whom)by(gender, title("Who received the informal payment? (by gender) (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
note("N=56; M=10; F=46",size(medium))) pie(1, color("$blue1")) pie(2, color("$lavendar"))  ///
noclockwise scheme(vg_lgndc) plabel(_all percent, format("%2.0f") ///
size(large) color(white))name(w2, replace)


graph pie,over(pay_whom)by(region, title("Who received the informal payment? (by strata) (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
note("N=56; R=35; U=21",size(medium))) pie(1, color("$blue1")) pie(2, color("$lavendar"))  ///
noclockwise scheme(vg_lgndc) plabel(_all percent, format("%2.0f") size(large) color(white))name(w3, replace)



gr combine w1 w2 w3, altshrink





//non ben failing to register because of political consideration


graph bar (percent),over(s3_20_4, gap(80) label(labcolor(black) labsize(large))) ///
$gr_deets2 title("Non ben. failing to register due to pol. consideration (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben  name(p1, replace)


graph bar (percent),over(s3_20_4, gap(80) label(labcolor(black) labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to pol. consideration by gender (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_nonben_gender  name(p2, replace)

graph bar (percent),over(s3_20_4, gap(80) label(labcolor(black)labsize(large))) ///
over(region, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to pol. consideration by strata (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_region  name(p3, replace)
 
graph bar (percent),over(s3_20_4, gap(80) label(labcolor(black)labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large))) ///
over(region, gap(80) label(labcolor(black) labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to pol. con. by gender and strata", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_g_r  name(p4, replace)


 
 gr combine p1 p2 p3 p4, altshrink 
 
 


//non ben failing to register because gov rep. does not allow


graph bar (percent),over(s3_20_1, gap(80) label(labcolor(black) labsize(large))) ///
$gr_deets2 title("Non ben. failing to register due to gov rep. not allowing (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben  name(g1, replace)


graph bar (percent),over(s3_20_1, gap(80) label(labcolor(black) labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to gov rep. not allowing by gender", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_gender  name(g2, replace)

graph bar (percent),over(s3_20_1, gap(80) label(labcolor(black)labsize(large))) ///
over(region, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to gov rep. not allowing by strata", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_region  name(g3, replace)
 
graph bar (percent),over(s3_20_1, gap(80) label(labcolor(black)labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large)))over(region, gap(80) ///
label(labcolor(black) labsize(large))) $gr_deets2 ///
title("Non ben. failing to reg. due to gov rep. not allowing (gen. & strata)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_g_r  name(g4, replace)


 
 gr combine g1 g2 g3 g4, altshrink 
 
 


//non beneficiary failing to register because of informal fees

graph bar (percent),over(s3_20_2, gap(80) label(labcolor(black) labsize(large))) ///
$gr_deets2 title("Non beneficiary failing to register because of informal fees (%)", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben  name(ci1, replace)


graph bar (percent),over(s3_20_2, gap(80) label(labcolor(black) labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register because of informal fees by gender", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_nonben_gender  name(ci2, replace)

graph bar (percent),over(s3_20_2, gap(80) label(labcolor(black)labsize(large))) ///
over(region, gap(80) label(labcolor(black)labsize(large))) $gr_deets2 ///
title("Non ben. failing to register because of informal fees by strata", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) ///
$gr_nonben_region  name(ci3, replace)
 
graph bar (percent),over(s3_20_2, gap(80) label(labcolor(black)labsize(large))) ///
over(gender, gap(80) label(labcolor(black)labsize(large))) ///
over(region, gap(80) label(labcolor(black) labsize(large))) $gr_deets2 ///
title("Non ben. failing to register due to informal fees by gender & strata", ///
justification(left) margin(b+1 t-1 l-1) bexpand size(large) color (black)) $gr_nonben_g_r  name(ci4, replace)


 
 gr combine ci1 ci2 ci3 ci4, altshrink 
 
 



